﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.rights
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int rights_id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(rights_id);
				}
			}
		}
			
	private void ShowInfo(int rights_id)
	{
		lcs.BLL.rights bll=new lcs.BLL.rights();
		lcs.Model.rights model=bll.GetModel(rights_id);
		this.lblrights_id.Text=model.rights_id.ToString();
		this.txtrights_name.Text=model.rights_name;
		this.txtrights_url.Text=model.rights_url;
		this.txtrights_order.Text=model.rights_order.ToString();
		this.txtparent_id.Text=model.parent_id.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtrights_name.Text.Trim().Length==0)
			{
				strErr+="rights_name不能为空！\\n";	
			}
			if(this.txtrights_url.Text.Trim().Length==0)
			{
				strErr+="rights_url不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtrights_order.Text))
			{
				strErr+="权限显示顺序格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtparent_id.Text))
			{
				strErr+="父权限节点ID格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int rights_id=int.Parse(this.lblrights_id.Text);
			string rights_name=this.txtrights_name.Text;
			string rights_url=this.txtrights_url.Text;
			int rights_order=int.Parse(this.txtrights_order.Text);
			int parent_id=int.Parse(this.txtparent_id.Text);


			lcs.Model.rights model=new lcs.Model.rights();
			model.rights_id=rights_id;
			model.rights_name=rights_name;
			model.rights_url=rights_url;
			model.rights_order=rights_order;
			model.parent_id=parent_id;

			lcs.BLL.rights bll=new lcs.BLL.rights();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","List.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
